<template>
	<om-page :title="pageTitle">
		<view class="om_hd_fix">
			<ot-search ref='search' cacheKey="search_menu_cache" 
			:isFocus="true" 
			:showWant="true"
			:hotList="hotList"
			@cancel="cancel" 
			@getSearchText="getSearchText">
			</ot-search>
		</view>
		<view class="page__bd" style="padding-top: 100rpx;">
			<uni-list>
				<!-- #ifdef APP-PLUS -->
				<view v-for="(item, index) in datas" :key="index">
					<uni-list-item
					:showArrow="false"
						:title="item.text"
						:thumb="'/static' + item.iconCls"
						@click="infoTab(item)"
					></uni-list-item>
				</view>
				<!-- #endif -->
				<!-- #ifndef APP-PLUS -->
				<view v-for="(item, index) in datas" :key="index">
					<uni-list-item
					:showArrow="false"
						:title="item.text"
						:thumb="'static' + item.iconCls"
						@click="infoTab(item)"
					></uni-list-item>
				</view>
				<!-- #endif -->
			</uni-list>
		 </view>
		 <tui-nomore  :visible="clickSeearch && !this.datas.length"></tui-nomore>
	</om-page>
</template>

<script>
	import { getUrl } from '@/static/js/common.js';
	export default {
		data() {
			return {
				hotList:[
					{h5url:"/pages/form/hr-kq-askleave/hr-kq-askleave",text:"请假",code:"HRS1201"},
					{h5url:"/pages/form/hr-kq-businessleave/new-kq-businessleave",text:"出差",code:"HRS1203"},
				],
				pageTitle:"",
				datas:[],
				menuList:[],
				clickSeearch:false
			}
		},
		methods: {
			cancel(e){
				this.datas=[]
			},
			getSearchText(e){
				this.clickSeearch = true
				if(e){
					this.datas = this.menuList.filter((item)=>{
						if(!item.text){
							return false
						}
						return item.text.indexOf(e) > -1
					})
				}else{
					this.cancel()
				}
			},
			infoTab(item){
				this.$refs.search.addhistory(item)
				var url = getUrl((item.h5url || item.url),{
					title: item.text,
					code: item.code
				})
				uni.navigateTo({
					url: url
				})
			}
		},
		onLoad(){
			let _that = this
			uni.getStorage({
				key: 'menu_cache',
				success(res) {
					_that.menuList = res.data;
				},
				fail() {
					_that.om.request('wxCommon/getMenu').then(res => {
						if (res.succeed) {
							var arr = []
							for(var i=0;i<res.value.length;i++){
								let group = res.value[i]
								for(var j=0;j<group.menu.length;j++){
									let m = group.menu[j]
									arr.push(m)
								}
							}
							uni.setStorage({
								key: 'menu_cache',
								data:arr
							})
							_that.menuList = arr
						}
					})
				}
			});
		}
	}
</script>

<style>

</style>
